#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

const std::string myenv = "HELLO=AAAAAAAAAAAAAA";

extern char** environ;

int main()
{

  putenv((char*)myenv.c_str());
  pid_t id = fork();
  if(id == 0)
  {
//    char* const argv[] = {
//      (char*)"ls",
//      (char*)"--color",
//      (char*)"-a",
//      (char*)"-l",
//      nullptr
//    };
    char *const argv[] = {
      (char*)"other",
      nullptr
    };
//  (void)argv;
    char *const env[] = 
    {
      (char*)"HELLO=bite",
      (char*)"HELLO1=bite1",
      (char*)"HELLO2=bite2",
      (char*)"HELLO3=bite3"
    };
    execvpe("./other",argv,environ);

    //execlp("ls","ls","--color","-a","-l",nullptr); 
    //execv("/usr/bin/ls",argv);

    //sleep(3);
    //child
    //execl("/bin/ls","ls","-l", "--color", "-a",nullptr);
    //execl("./other","other",nullptr);
    //execl("/usr/bin/python","python", "text.py",nullptr);
    //execl("/bin/bash","bash","text.sh",nullptr);
    exit(1);
  }
  //father
  pid_t rid = waitpid(id,nullptr,0);
  if(rid > 0)
  {
    printf("等待子进程成功\n!");
  } 
  //execl("/bin/ls","ls","-l","-a",nullptr);
  //execl("/usr/bin/top","top",nullptr);
  // printf("我是myexec,pid:%d\n",getpid());
  // execl("./other","other",nullptr);
  
  //printf("execl return val:%d\n",n);
  
  return 0;
}
